package com.hy.mydesktop.client.mvc.desktop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



import com.extjs.gxt.desktop.client.Desktop;
import com.extjs.gxt.desktop.client.Shortcut;
import com.extjs.gxt.desktop.client.StartMenu;
import com.extjs.gxt.desktop.client.TaskBar;
import com.extjs.gxt.samples.resources.client.TestData;
import com.extjs.gxt.samples.resources.client.model.Stock;
import com.extjs.gxt.ui.client.Registry;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelIconProvider;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ToolButton;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Widget;
import com.hy.mydesktop.client.mvc.desktop.ShortcutPresenter.Display;
import com.hy.mydesktop.client.mvc.logindialog.LoginDialog;



public class ShortcutView implements Display{
	
	
	public ShortcutView(Shortcut shortcut) {
		super();
		this.shortcut = shortcut;
	}

	private Shortcut shortcut = null;
	
	
	public Shortcut getShortcut() {
		return shortcut;
	}

	public void setShortcut(Shortcut shortcut) {
		this.shortcut = shortcut;
	}

	

	/*
	
	private GxtComponentMetaModel getDesktopMetaModel_Shortcut() {
		Map<String, Object> map1=new HashMap<String, Object>();
		map1.put("component_model_type", ComponentTypeEnum.DESKTOP_MODEL);
		GxtComponentMetaNodeModel node1=new GxtComponentMetaNodeModel(map1, 1, 6);
		
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		//TODO map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		GxtComponentMetaNodeModel node2=new GxtComponentMetaNodeModel(map2, 2, 3);
		
		Map<String, Object> map3=new HashMap<String, Object>();
		map3.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		GxtComponentMetaNodeModel node3=new GxtComponentMetaNodeModel(map3, 4, 5);
		
		List<GxtComponentMetaNodeModel> list = new ArrayList<GxtComponentMetaNodeModel>();
		list.add(node1);
		list.add(node2);
		list.add(node3);
		GxtComponentMetaModel gxtComponentMetaModel = new GxtComponentMetaModel();
		gxtComponentMetaModel.setList(list);
		
		return gxtComponentMetaModel;
		
	}
	private GxtComponentMetaModel getDesktopMetaModel() {
		Map<String, Object> map1=new HashMap<String, Object>();
		map1.put("component_model_type", ComponentTypeEnum.DESKTOP_MODEL);
		GxtComponentMetaNodeModel node1=new GxtComponentMetaNodeModel(map1, 1, 6);
		
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		//TODO map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		GxtComponentMetaNodeModel node2=new GxtComponentMetaNodeModel(map2, 2, 3);
		
		Map<String, Object> map3=new HashMap<String, Object>();
		map3.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		GxtComponentMetaNodeModel node3=new GxtComponentMetaNodeModel(map3, 4, 5);
		
		List<GxtComponentMetaNodeModel> list = new ArrayList<GxtComponentMetaNodeModel>();
		list.add(node1);
		list.add(node2);
		list.add(node3);
		GxtComponentMetaModel gxtComponentMetaModel = new GxtComponentMetaModel();
		gxtComponentMetaModel.setList(list);
		
		return gxtComponentMetaModel;
		
	}
	
	*//**
	 * 模拟调用后台逻辑后，传回来的对象
	 *//*
	 private Window createGridWindow() {
		    Window w = new Window();
		    w.setIcon(IconHelper.createStyle("icon-grid"));
		    w.setMinimizable(true);
		    w.setMaximizable(true);
		    w.setHeading("Grid Window");
		    w.setSize(500, 400);
		    w.setLayout(new FitLayout());
		    
		    w.setId("999");

		    GroupingStore<Stock> store = new GroupingStore<Stock>();
		    store.add(TestData.getCompanies());
		    store.groupBy("industry");

		    ColumnConfig company = new ColumnConfig("name", "Company", 60);
		    ColumnConfig price = new ColumnConfig("open", "Price", 20);
		    price.setNumberFormat(NumberFormat.getCurrencyFormat());
		    ColumnConfig change = new ColumnConfig("change", "Change", 20);
		    ColumnConfig industry = new ColumnConfig("industry", "Industry", 20);
		    ColumnConfig last = new ColumnConfig("date", "Last Updated", 20);
		    last.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/y"));

		    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
		    config.add(company);
		    config.add(price);
		    config.add(change);
		    config.add(industry);
		    config.add(last);

		    final ColumnModel cm = new ColumnModel(config);

		    GroupingView view = new GroupingView();
		    view.setForceFit(true);
		    view.setGroupRenderer(new GridGroupRenderer() {
		      public String render(GroupColumnData data) {
		        String f = cm.getColumnById(data.field).getHeader();
		        String l = data.models.size() == 1 ? "Item" : "Items";
		        return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
		      }
		    });

		    Grid<Stock> grid = new Grid<Stock>(store, cm);
		    grid.setView(view);
		    grid.setBorders(true);

		    w.add(grid);
		    return w;
		  }
	 
	 *//**
		 * 模拟调用后台逻辑后，传回来的对象
		 *//*
		 private Window createGridWindow2() {
			    Window w = new Window();
			    w.setIcon(IconHelper.createStyle("icon-grid"));
			    w.setMinimizable(true);
			    w.setMaximizable(true);
			    w.setHeading("Grid Window222222");
			    w.setSize(500, 400);
			    w.setLayout(new FitLayout());

			    GroupingStore<Stock> store = new GroupingStore<Stock>();
			    store.add(TestData.getCompanies());
			    store.groupBy("industry");

			    ColumnConfig company = new ColumnConfig("name", "Company", 60);
			    ColumnConfig price = new ColumnConfig("open", "Price", 20);
			    price.setNumberFormat(NumberFormat.getCurrencyFormat());
			    ColumnConfig change = new ColumnConfig("change", "Change", 20);
			    ColumnConfig industry = new ColumnConfig("industry", "Industry", 20);
			    ColumnConfig last = new ColumnConfig("date", "Last Updated", 20);
			    last.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/y"));

			    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
			    config.add(company);
			    config.add(price);
			    config.add(change);
			    config.add(industry);
			    config.add(last);

			    final ColumnModel cm = new ColumnModel(config);

			    GroupingView view = new GroupingView();
			    view.setForceFit(true);
			    view.setGroupRenderer(new GridGroupRenderer() {
			      public String render(GroupColumnData data) {
			        String f = cm.getColumnById(data.field).getHeader();
			        String l = data.models.size() == 1 ? "Item" : "Items";
			        return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
			      }
			    });

			    Grid<Stock> grid = new Grid<Stock>(store, cm);
			    grid.setView(view);
			    grid.setBorders(true);

			    w.add(grid);
			    return w;
			  }
		 
	 
	*//**
	 * 模拟从后台传过来的关于Shortcut控件的元模型信息
	 *//*
	private GxtComponentMetaNodeModel getGxtComponentMetaNodeModel2() {
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		//TODO map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
			Map<String,Object> codes2 = new HashMap<String, Object>();
			//添加需要监听的事件类型，指定由某一个控制器响应，控制器内部应该如何响应（附加参数和数据）
			*//**
			 * 00_01_02为特征码
			 * 或者是 控制器的唯一标识
			 *//*
				Map<String,Object> subMap = new HashMap<String, Object>();
					EventStructureMetaModel eventStructureMetaModel = new EventStructureMetaModel();
					eventStructureMetaModel.setControllerId("shortcutController02");
					eventStructureMetaModel.setResponseModeId("00_02_02");
				subMap.put("eventstructuremetamodel", eventStructureMetaModel);
			codes2.put("0003", subMap);
			//codes1.add("0002");
		map2.put("registereventtypes", codes2);
		map2.put("text", "2222222222createWindow-----LoginView----AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER");	
		GxtComponentMetaNodeModel node2=new GxtComponentMetaNodeModel(map2);
		return node2;
	}
	
	*//**
	 * 模拟从后台传过来的关于Shortcut控件的元模型信息
	 *//*
	private GxtComponentMetaNodeModel getGxtComponentMetaNodeModel() {
		Map<String, Object> map2=new HashMap<String, Object>();
		map2.put("component_model_type", ComponentTypeEnum.SHORTCUT_MODEL);
		//TODO map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
		map2.put("appEventType", AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
			Map<String,Object> codes2 = new HashMap<String, Object>();
			//添加需要监听的事件类型，指定由某一个控制器响应，控制器内部应该如何响应（附加参数和数据）
			*//**
			 * 00_01_02为特征码
			 * 或者是 控制器的唯一标识
			 *//*
				Map<String,Object> subMap = new HashMap<String, Object>();
					EventStructureMetaModel eventStructureMetaModel = new EventStructureMetaModel();
					eventStructureMetaModel.setControllerId("shortcutController01");
					eventStructureMetaModel.setResponseModeId("00_01_02");
				subMap.put("eventstructuremetamodel", eventStructureMetaModel);
			codes2.put("0003", subMap);
			//codes1.add("0002");
		map2.put("registereventtypes", codes2);
		map2.put("text", "11111111111createWindow-----LoginView----AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER");	
		GxtComponentMetaNodeModel node2=new GxtComponentMetaNodeModel(map2);
		return node2;
	}
	 
	private void itemSelected(ComponentEvent ce) {
	    Window w;
	    if (ce instanceof MenuEvent) {
	      MenuEvent me = (MenuEvent) ce;
	      w = me.getItem().getData("window");
	    } else {
	      w = ce.getComponent().getData("window");
	    }
	    if (!desktop.getWindows().contains(w)) {
	      desktop.addWindow(w);
	    }
	    if (w != null && !w.isVisible()) {
	      w.show();
	    } else {
	      w.toFront();
	    }
	    
	    
		
	    
	}*/

	@Override
	public boolean add(Widget widget) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Button getLoginButton() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TextField<String> getUserNameTextField() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TextField<String> getPasswordTextField() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public LoginDialog getLoginDialog() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Component getComponent() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setComponent(Component component) {
		// TODO Auto-generated method stub
		
	}
}
